/**
 * 
 * @since  2009/2/16
 * @author ashen,xthsky
 * 
 * Description: 景点信息的Controller。
 * 
 */
package controller.api;

import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

import model.Spot;
import net.sf.json.JSONObject;

import org.jdom.Document;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;

import db.DAOFactory;
import api.ResultXml;


public class SpotController extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	public SpotController() {
		super();
	}

	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/xml");
		response.setCharacterEncoding("utf-8");
		PrintWriter out = response.getWriter();

		String spotName = request.getPathInfo().substring(1);
		spotName = new String(spotName.getBytes("ISO-8859-1"), "UTF-8");

		Spot s = DAOFactory.getSpotDAO().findByName(spotName);
		tools.OutputXml.output(s, response);
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		System.out.println("receive post request.");
		System.out.println(request.getParameter("id"));
	}

	/**
	 * The doPut method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to put.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPut(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		System.out.println("receive put request.");
		
		Scanner s = new Scanner(request.getInputStream());
		while(s.hasNextLine())
			System.out.println(s.nextLine());

		
	}
	
	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occurs
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}
